<template>
  <!-- 这是薪酬页 -->
  <div class="PayIndex">
    <div class="header-wrapper">
      <yd-navbar title="薪酬信息" bgcolor='#fdd333' color='#fff' height='45px' fontsize='16px'>
      </yd-navbar>
    </div>
     <div class="year-drop-down-box">
    <select id="year" v-model="myDate" @change="show2">
        <option :value="item"  v-for="item of yearData" :key="item.id" >{{item}}</option>
    </select>
  </div>
      <NoMoney v-show="show"></NoMoney>
      <HaveMoney :list='list' @sendMonth='sendMonth'></HaveMoney>
    <v-nav></v-nav>
  </div>
</template>
<script>
import NoMoney from '../NoMoney/NoMoney'
import HaveMoney from '../HaveMoney/HaveMoney'
import Nav from '@/components/public/nav'
import apis from '../../../../../static/js/apis.js'
export default {
  data () {
    return {
      show: true,
      yearData: [], // 年
      myDate: [], // 数组年
      arrlist: [], // 接收数据
      list: [],
      month: ''
    }
  },
  components: {
    apis,
    NoMoney,
    HaveMoney,
    'v-nav': Nav
    // FadeAnimation
  },
  created () {
    var year = new Date()
    this.yearData.push(
      year.getFullYear(),
      year.getFullYear() - 1,
      year.getFullYear() - 2
    )
    this.myDate = this.yearData[0]
    this.$axios
      .post(
        apis + '/app/salaryapp/getone',
        this.confusion(
          JSON.stringify({
            year: this.myDate,
            month: year.getMonth() + 1
          })
        ),
        {
          headers: {
            Authorization: 'Bearer ' + JSON.parse(window.localStorage.getItem('userInfo')).token,
            'Content-Type': 'application/json;charset=UTF-8',
            'Cache-Control': 'no-cache',
            isApp: 'isApp'
          }
        }
      )
      .then(response => {
        this.arrlist = response.data
        if (this.arrlist.length === 0) {
          this.show = true
        } else {
          this.show = false
        }
        if (this.list.length !== 0) {
          this.list = []
          this.arrlist.forEach(ele => {
            var obj = {}
            var time = ele.salarytime
            var changeTiem = time.split(' ')
            obj.salarytime = changeTiem[0]
            obj.basesalary = ele.basesalary
            obj.countsalary = ele.countsalary
            obj.totalsalary = ele.totalsalary
            this.list.push(obj)
          })
        } else {
          this.arrlist.forEach(ele => {
            var obj = {}
            var time = ele.salarytime
            var changeTiem = time.split(' ')
            obj.salarytime = changeTiem[0]
            obj.basesalary = ele.basesalary
            obj.countsalary = ele.countsalary
            obj.totalsalary = ele.totalsalary
            this.list.push(obj)
          })
        }
      })
      .catch(error => {
        console.log(error)
        this.$dialog.toast({
          mes: '服务器异常'
        })
      })
  },
  methods: {
    sendMonth (val) {
      // alert('我接受到你传递过来的月份是' + val)
      this.month = val
      this.$axios
        .post(
          apis + '/app/salaryapp/getone',
          this.confusion(
            JSON.stringify({
              year: this.myDate,
              month: this.month
            })
          ),
          {
            headers: {
              Authorization: 'Bearer ' + JSON.parse(window.localStorage.getItem('userInfo')).token,
              'Content-Type': 'application/json;charset=UTF-8',
              'Cache-Control': 'no-cache',
              isApp: 'isApp'
            }
          }
        )
        .then(response => {
          this.arrlist = response.data
          if (this.arrlist.length === 0) {
            this.show = true
          } else {
            this.show = false
          }
          if (this.list.length !== 0) {
            this.list = []
            this.arrlist.forEach(ele => {
              var obj = {}
              var time = ele.salarytime
              var changeTiem = time.split(' ')
              obj.salarytime = changeTiem[0]
              obj.basesalary = ele.basesalary
              obj.countsalary = ele.countsalary
              obj.totalsalary = ele.totalsalary
              this.list.push(obj)
            })
          } else {
            this.arrlist.forEach(ele => {
              var obj = {}
              var time = ele.salarytime
              var changeTiem = time.split(' ')
              obj.salarytime = changeTiem[0]
              obj.basesalary = ele.basesalary
              obj.countsalary = ele.countsalary
              obj.totalsalary = ele.totalsalary
              this.list.push(obj)
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$dialog.toast({
            mes: '服务器异常'
          })
        })
    },
    show2 () {
      this.$axios
        .post(
          apis + '/app/salaryapp/getone',
          this.confusion(
            JSON.stringify({
              year: this.myDate,
              month: this.month
            })
          ),
          {
            headers: {
              Authorization: 'Bearer ' + JSON.parse(window.localStorage.getItem('userInfo')).token,
              'Content-Type': 'application/json;charset=UTF-8',
              'Cache-Control': 'no-cache',
              isApp: 'isApp'
            }
          }
        )
        .then(response => {
          this.arrlist = response.data
          if (this.arrlist.length === 0) {
            this.show = true
          } else {
            this.show = false
          }
          if (this.list.length !== 0) {
            this.list = []
            this.arrlist.forEach(ele => {
              var obj = {}
              var time = ele.salarytime
              var changeTiem = time.split(' ')
              obj.salarytime = changeTiem[0]
              obj.basesalary = ele.basesalary
              obj.countsalary = ele.countsalary
              obj.totalsalary = ele.totalsalary
              this.list.push(obj)
            })
          } else {
            this.arrlist.forEach(ele => {
              var obj = {}
              var time = ele.salarytime
              var changeTiem = time.split(' ')
              obj.salarytime = changeTiem[0]
              obj.basesalary = ele.basesalary
              obj.countsalary = ele.countsalary
              obj.totalsalary = ele.totalsalary
              this.list.push(obj)
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$dialog.toast({
            mes: '服务器异常'
          })
        })
    }
  }
}
</script>
<style scoped>
.header-wrapper {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 5;
}
.icon-back {
  color: #fff;
  font-size: 20px;
}
.year-drop-down-box {
  text-align: center;
  height: 42px;
  position: fixed;
  top: 45px;
  width: 100%;
  z-index: 5;
  background: #fff;
  border-bottom: 1px solid #e1e1e1;
}

#year {
  border: 0;
  background-color: #f1f1f1;
  background: transparent;
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
  background: url("./../../../../assets/img/xiala.png") no-repeat right center transparent;
  padding-right: 25px;
  -webkit-background-size: 30px;
  background-size: 30px;
  margin-right: -20px;
  outline: none;
  position: absolute;
  top: 25%;
  left: 45%;
  font-size: 15px;
}
</style>
